﻿using Learun.Util;
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;

namespace Learun.Application.TwoDevelopment.ZZDT_EC
{
    /// <summary>
    /// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
    /// Copyright (c) 2013-2018 Hexagon PPM
    /// 创 建：超级管理员
    /// 日 期：2022-07-04 10:00
    /// 描 述：同步关联表
    /// </summary>
    public class ec_synrel_tableBLL : ec_synrel_tableIBLL
    {
        private ec_synrel_tableService ec_synrel_tableService = new ec_synrel_tableService();

        #region 获取数据

        /// <summary>
        /// 获取列表数据
        /// <summary>
        /// <returns></returns>
        public IEnumerable<ec_synrel_tableEntity> GetList(string queryJson)
        {
            try
            {
                return ec_synrel_tableService.GetList(queryJson);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }

        /// <summary>
        /// 获取实体数据
        /// <param name="keyValue">主键</param>
        /// <summary>
        /// <returns></returns>
        public ec_synrel_tableEntity GetEntity(string keyValue)
        {
            try
            {
                return ec_synrel_tableService.GetEntity(keyValue);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }

        #endregion

        #region 提交数据

        /// <summary>
        /// 保存实体数据（新增、修改）
        /// <param name="keyValue">主键</param>
        /// <summary>
        /// <returns></returns>
        public void SaveEntity(string mainBusinessTableID, List<ec_synrel_tableEntity> entityList)
        {
            try
            {
                if(entityList!=null&& entityList.Count > 0)
                {
                    string curUserID = LoginUserInfo.Get().userId;
                    entityList = entityList.Select(x => { x.CreateUserID = curUserID; x.CreateTime = DateTime.Now;return x; }).ToList();
                }
                
                ec_synrel_tableService.SaveEntity(mainBusinessTableID, entityList);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }

        #endregion

    }
}
